package org.zhangchao.poi.excel.operate;

import java.io.File;
import java.io.InputStream;

import org.zhangchao.poi.excel.common.ExcelEnum;
import org.zhangchao.poi.excel.interceptor.ExcelHandlerInterceptorStack;
import org.zhangchao.poi.excel.interceptor.ExcelProcessModelHandlerInterceptor;

/**
 * 
 * @author ZhangChao
 *
 * @param <E>
 */
public class ExcelProcessModelOperate<E> extends ExcelBaseOperate<E> {
	

	/**
	 * 构建处理器
	 * @param type
	 * @throws Exception
	 */
	public ExcelProcessModelOperate(ExcelEnum type) throws Exception {
		super(type);
	}
	
	/**
	 * 构建处理器
	 * @param type
	 * @param templateFileName
	 * @param clazz
	 * @throws Exception
	 */
	public ExcelProcessModelOperate(ExcelEnum type, String templateFileName, Class<?> clazz) throws Exception {
		super(type, templateFileName);
		init(clazz);
	}
	
	/**
	 * 构建处理器
	 * @param type
	 * @param templateFile
	 * @param clazz
	 * @throws Exception
	 */
	public ExcelProcessModelOperate(ExcelEnum type, File templateFile, Class<?> clazz) throws Exception {
		super(type, templateFile);
		init(clazz);
	}
	
	/**
	 * 构建处理器
	 * @param type
	 * @param templateInp
	 * @param clazz
	 * @throws Exception
	 */
	public ExcelProcessModelOperate(ExcelEnum type, InputStream templateInp, Class<?> clazz) throws Exception {
		super(type, templateInp);
		init(clazz);
	}
	
	/**
	 * 构建处理器
	 * @param type
	 * @param clazz
	 * @throws Exception
	 */
	public ExcelProcessModelOperate(ExcelEnum type, Class<?> clazz) throws Exception {
		super(type);
		init(clazz);
	}
	
	
	/**
	 * 初始化设置
	 */
	private void init(Class<?> clazz) {
		//穿件拦截器栈
		setHandlerStack(new ExcelHandlerInterceptorStack());
		//excel 拦截器--把excle行封装成对象
		ExcelProcessModelHandlerInterceptor epmhi = new ExcelProcessModelHandlerInterceptor(clazz);
		getHandlerStack().add(epmhi);
	}

}
